package com.loong.seller.controller.backend;

import com.loong.common.mvc.BaseBackendController;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonInsert;
import com.loong.common.validator.group.CommonUpdate;
import com.loong.seller.common.backend.param.ShopDeliveryRuleParam;
import com.loong.seller.handler.ShopDeliveryRuleHandler;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


/**
 * @Description:
 * @Author: hzp
 * @Date: 2020-12-16 14:12
 */
@RestController
@RequestMapping("/manage/seller/shopDeliveryRule")
public class ShopDeliveryRuleController extends BaseBackendController {
    @Resource
    private ShopDeliveryRuleHandler shopDeliveryRuleHandler;

    /**
     * 保存店铺配送方式规则
     * @param param
     * @return 200
     */
    @PostMapping("save")
    public Result save(@Validated(value = {CommonInsert.class}) ShopDeliveryRuleParam param){
        param.setId(null);
        return   handlerExecutor.execute(()->shopDeliveryRuleHandler.save(param));
    }

    /**
     * 更新店铺配送方式规则
     * @param param
     * @return 200
     */
    @PostMapping("update")
    public Result update(@Validated(value = {CommonUpdate.class}) ShopDeliveryRuleParam param){
        return   handlerExecutor.execute(()->shopDeliveryRuleHandler.update(param));
    }
    /**
     * 批量删除店铺配送方式规则
     * @param ids
     * @return 200
     */
    @PostMapping("delete")
    public Result deletes(@RequestParam("ids") List<Long> ids){
        if(CollectionUtils.isEmpty(ids))return null;
        return   handlerExecutor.execute(()->shopDeliveryRuleHandler.delete(ids));
    }




}
